var app = getApp(),
  $ = require("../../utils/httpHelper.js");
Page({
  data: {
    username: '',
    isedit: true,
    pwd: '',
    pwdc: '',
    oldp: '',
    newp: '',
    comp: ''
  },
  onLoad: function (options) {
    let par = {
      rd_session: app.globalData.userInfo.rd_session
    }
    $.httpPost("check_pass", par, (data, err) => {
      this.setData({
        isedit: data.data
      })
    })
  },
  getpwd(e) {
    this.setData({
      pwd: e.detail.value
    })
  },
  getpwdc(e) {
    this.setData({
      pwdc: e.detail.value
    })
  },
  getoldp(e) {
    this.setData({
      oldp: e.detail.value
    })
  },
  getnewp(e) {
    this.setData({
      newp: e.detail.value
    })
  },
  getcomp(e) {
    this.setData({
      comp: e.detail.value
    })
  },
  editpass() {
    if (app.check_empty(this.data.oldp) || app.check_empty(this.data.newp) || app.check_empty(this.data.comp)) {
      wx.showToast({
        title: '不能是空',
      })
    } else {
      let par = {
        rd_session: app.globalData.userInfo.rd_session,
        old_pass: this.data.oldp,
        pass: this.data.newp,
        confirm_pass: this.data.comp
      }
      $.httpPost("edit_pass", par, (data, err) => {
        wx.showToast({
          title: data.message,
        })
        if (data.result == 'success') {
          wx.redirectTo({
            url: '/pages/mine/money'
          })
        }
      })
    }
  },
  submitpass() {
    if (app.check_empty(this.data.pwd) || app.check_empty(this.data.pwdc)) {
      wx.showToast({
        title: '不能是空',
      })
    } else {
      let par = {
        rd_session: app.globalData.userInfo.rd_session,
        pass: this.data.pwd,
        confirm_pass: this.data.pwdc
      }
      $.httpPost("set_pass", par, (data, err) => {
        wx.showToast({
          title: data.message,
        })
        if (data.result == 'success') {
          wx.redirectTo({
            url: '/pages/mine/money'
          })
        }
      })
    }
  }


})
